//
//  TMNetworkConfig.h
//  Pods
//
//  Created by LIJUN on 16/8/24.
//
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>

typedef id (^TMRequestPreprocessResponseBlock)(NSURLSessionTask *sessionTask, id responseObject, Class modelClass);

typedef BOOL (^TMRequestEstimateTokenExpireBlock)(NSURLSessionTask *sessionTask, id responseObject);
typedef BOOL (^TMRequestEstimateSuccessBlock)(NSURLSessionTask *sessionTask, id responseObject);

typedef void (^TMRequestNetworkErrorCommonProcessBlock)(NSError *error);
typedef void (^TMRequestTokenExpireCommonProcessBlock)(id responseObject);
typedef void (^TMRequestFailureCommonProcessBlock)(id responseObject);

@protocol TMURLFilterDelegate <NSObject>

@required
- (void)filterUrl:(NSString *)path
     headerParams:(NSMutableDictionary **)headerParams
      queryParams:(NSMutableDictionary **)queryParams
       formParams:(id *)formParams
        withToken:(BOOL)withToken;

@end

@protocol TMRequestAccessoryDelegate <NSObject>

@optional
- (void)requestWillStart:(NSString *)path;
- (void)requestWillComplete:(NSString *)path;

@end

@interface TMNetworkConfig : NSObject

@property (nonatomic, copy) NSString *baseUrl;
@property (nonatomic, assign) NSInteger maxConcurrentOperationCount;
@property (nonatomic, assign) NSTimeInterval requestTimeoutInterval;
@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;
@property (nonatomic, weak) id<TMURLFilterDelegate> urlFilterDelegate;
@property (nonatomic, readonly) NSMutableArray *accessoryDelegateArray;

@property (nonatomic, copy) TMRequestPreprocessResponseBlock preprocessResponseBlock;
@property (nonatomic, copy) TMRequestEstimateTokenExpireBlock estimateTokenExpireBlock;
@property (nonatomic, copy) TMRequestEstimateSuccessBlock estimateSuccessBlock;

@property (nonatomic, copy) TMRequestNetworkErrorCommonProcessBlock networkErrorProcessBlock;
@property (nonatomic, copy) TMRequestTokenExpireCommonProcessBlock tokenExpireProcessBlock;
@property (nonatomic, copy) TMRequestFailureCommonProcessBlock failureProcessBlock;

- (void)addAccessory:(id<TMRequestAccessoryDelegate>)accessoryDelegate;
- (void)removeAccessory:(id<TMRequestAccessoryDelegate>)accessoryDelegate;

+ (TMNetworkConfig *)sharedConfig;

@end
